package com.formiaomiao.demain.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.formiaomiao.demain.R;

public class UseGlideUtils {

    /**
     * 加载图片
     *
     * @param context
     * @param file
     * @param iv
     */
    @SuppressLint("CheckResult")
    public static void setGlide(Context context, Object file, ImageView iv) {
        RequestOptions options = RequestOptions.circleCropTransform();
        options.bitmapTransform(new CircleCrop());
        options.skipMemoryCache(true);
        options.diskCacheStrategy(DiskCacheStrategy.NONE);
        options.error(R.mipmap.ic_launcher);
        try {
            Glide.with(context).load(file)
                    .apply(options).into(iv);
        } catch (Exception e) {
            Glide.with(context).load(R.mipmap.ic_launcher)
                    .apply(options).into(iv);
        }
    }

    @SuppressLint("CheckResult")
    public static void setAddGlide(Context context, Object file, ImageView iv) {
        RequestOptions options = RequestOptions.centerInsideTransform();
        options.skipMemoryCache(true);
        options.diskCacheStrategy(DiskCacheStrategy.NONE);
        options.error(R.mipmap.ic_launcher);
        Glide.with(context).load(file).apply(options).into(iv);
    }

}
